
function handleView(o)
{
if(IsNull(o) || o.options.length == 0)
{
return;
}


var sOriginalViewId = crmGrid.GetParameter("viewid");




if(o.DataValue == LOCID_SEARCH_RESULTS)
crmGrid.SetParameter("viewid", SavedQuerySelector.quickFindQuery);
else
crmGrid.SetParameter("viewid", o.DataValue);

crmGrid.SetParameter("quickfind", "");
crmGrid.SetParameter("filter", "");
crmGrid.SetParameter("filterDisplay", "");
crmGrid.SetParameter("viewtype", getViewType(o));
var handler = new onGridRefreshCompleteHandler(o, sOriginalViewId);
crmGrid.Reset(handler.OnComplete);
}
function onGridRefreshCompleteHandler(oViewSelector, sOriginalView)
{
var oViewSelect = oViewSelector;
var sOriginalViewId = sOriginalView;
this.OnComplete = _handleComplete;
function _handleComplete(oResult)
{
if(!oResult.Success)
{

oViewSelect.DataValue = sOriginalViewId;



crmGrid.SetParameter("viewid", sOriginalViewId);
crmGrid.SetParameter("viewtype", getViewType(oViewSelect));
crmGrid.Reset();
}

quickFindReset(oViewSelect);
}
}



function getViewType(oSelect)
{


var sViewType = oSelect.options[oSelect.selectedIndex].Type;


if (IsNull(sViewType))
{
sViewType = SavedQuery;
}


return sViewType;
}
function quickFindReset(oSelect)
{


oSelect.DeleteOption(LOCID_SEARCH_RESULTS);


if(document.getElementById('crmGrid_JumpBar'))
{
if (crmGrid_JumpBar)
{
if (crmGrid.Version && crmGrid.Version == "3.0")
{
crmGrid_JumpBar.Reset();
}
else
{
crmGrid_JumpBar.filter(true);
}
}
}

if (typeof(quickFindContainer) != "undefined")
{
quickFindContainer.NotifyExitedQuickFind();
}
else if (typeof(findCriteria) != "undefined")
{
findCriteria.value = "";
}
}
function clearFind()
{
if (typeof(quickFindContainer) != "undefined")
{
quickFindContainer.NotifyExitedQuickFind();
}
else if (typeof(findCriteria) != "undefined")
{
findCriteria.value = "";
}

crmGrid.SetParameter("viewtype", SavedQuery);
crmGrid.SetParameter("quickfind", "");
crmGrid.SetParameter("filter", "");
crmGrid.SetParameter("filterDisplay", "");


var oControl = document.all("crmDateSelector");
if (!IsNull(oControl))
{
if (oControl.tagName == "SELECT")
{
oControl.value = "All";

oGrid = document.all["crmGrid"];

if (IsNull(oGrid))
{
return;
}

oGrid.SetParameter("scheduledend", oControl.DataValue);
}
}

crmGrid.ClearPagingCookie();

crmGrid.Reset();
}
function quickFind()
{
try
{
var sFindCriteria = Trim(findCriteria.value.replace(/[\*]+/, "*"));

sFindCriteria = sFindCriteria.replace(/^ +| +$/g, "");
findCriteria.value = sFindCriteria;
if (sFindCriteria == "")
{
alert(LOCID_SEARCH_ALERT_NO_CRITERIA);
return false;
}

crmGrid.SetParameter("viewtype", SavedQuery);
crmGrid.SetParameter("quickfind", sFindCriteria);
crmGrid.SetParameter("filter", "");
crmGrid.SetParameter("filterDisplay", "");


var oControl = document.all("crmDateSelector");
if (!IsNull(oControl))
{
if (oControl.tagName == "SELECT")
{
oControl.value = "All";

oGrid = document.all["crmGrid"];

if (IsNull(oGrid))
{
return false;
}

oGrid.SetParameter("scheduledend", oControl.DataValue);
}
}

crmGrid.ClearPagingCookie();
if (crmGrid.GetParameter("viewid") != SavedQuerySelector.quickFindQuery)
{
crmGrid.SetParameter("viewid", SavedQuerySelector.quickFindQuery);

crmGrid.Reset();
}
else
{

crmGrid.PageNumber = 1;
}
if (SavedQuerySelector.value != LOCID_SEARCH_RESULTS )
{


var i;

for( i=0; i< SavedQuerySelector.length;i++){
if(SavedQuerySelector.options[i].value == LOCID_SEARCH_RESULTS){
SavedQuerySelector[i].selectedIndex =i;
break;
}
}
if(i>=SavedQuerySelector.length){
var o = SavedQuerySelector.AddOption(LOCID_SEARCH_RESULTS, LOCID_SEARCH_RESULTS);
o.Type = SavedQuery;

SavedQuerySelector.selectedIndex = SavedQuerySelector.length-1;
}



}

if(document.getElementById('crmGrid_JumpBar'))
{
crmGrid_JumpBar.Reset();
}

}
catch (e)
{
alert(LOCID_SEARCH_LIST_NOT_OPEN);
return false;
}
return true;
}

function window.onresize()
{
if (typeof(tdWatermark) != "undefined")
{
tdWatermark.style.display = (document.body.clientWidth <= 600) ? "none" : "";
}
}
function HandleBackButtonIssues(sPageCode)
{


try
{
if (!IsNull(sPageCode) && sPageCode != "")
{
top.setNav(sPageCode);
}
}
catch(e){}
if (typeof(findCriteria) != "undefined")
{
if (findCriteria.defaultValue != findCriteria.value)
{
findCriteria.value = findCriteria.defaultValue;
}
}

if (typeof(SavedQuerySelector) != "undefined")
{
if (SavedQuerySelector.DefaultValue != SavedQuerySelector.DataValue)
{
SavedQuerySelector.value = SavedQuerySelector.DefaultValue;
}
}
}
function openAdvFind()
{

var oAppViewSelector = null;
if(typeof(SavedQuerySelector)!="undefined")
{
oAppViewSelector = SavedQuerySelector;
}
else if(typeof(ViewArea)!="undefined" && typeof(ViewArea.SavedQuerySelector)!="undefined")
{

oAppViewSelector = ViewArea.SavedQuerySelector;
}
var win = window, fp = null, iWidth, iHeight;

while(typeof(fp=win.GetWindowInformation)=="undefined" && win.parent != win)
{
win = win.parent;
}

if(IsNull(fp))
{
iWidth = 700;
iHeight = 600;
}
else
{
var oWindowInfo = fp(UserQuery);
iWidth = oWindowInfo.Width;
iHeight = oWindowInfo.Height;
}

var sViewId, sViewType, sOTC;
if(!IsNull(oAppViewSelector))
{

with(oAppViewSelector)
{
sViewId = value;
sViewType = options[oAppViewSelector.selectedIndex].Type;
sOTC = ReturnedTypeCode;
}
}
else if(typeof(crmGrid)!="undefined")
{

with(crmGrid)
{
sViewId = GetParameter("viewid");
sViewType = GetParameter("viewtype");
sOTC = GetParameter("otc");
}
}

if(!IsNull(sViewId) && !IsNull(sViewType) && !IsNull(sOTC))
{

openStdWin(prependOrgName("/AdvancedFind/AdvFind.aspx?EntityCode=" + sOTC + "&QueryId=" + sViewId + "&ViewType=" + sViewType), "Search", iWidth, iHeight);
}
else if(!IsNull(sOTC))
{

openStdWin(prependOrgName("/AdvancedFind/AdvFind.aspx?EntityCode=" + sOTC), "Search", iWidth, iHeight);
}
else
{
openStdWin(prependOrgName("/AdvancedFind/AdvFind.aspx"), "Search", iWidth, iHeight);
}
}
